import type { ConsultType } from '@/enums'
import type { ConsultIllness, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'consult',
  () => {
    // 问诊信息
    const consult = ref<PartialConsult>({})

    // 选择问诊类型
    const setConsultType = (type: ConsultType) => {
      consult.value.type = type
    }

    // 设置极速问诊类型
    const setIllnessType = (type: 0 | 1) => (consult.value.illnessType = type)

    // 选择极速问诊科室
    const setDepId = (id: string) => (consult.value.depId = id)

    //填写病情描述
    const setIllness = (consultIllness: ConsultIllness) => {
      consult.value.illnessDesc = consultIllness.illnessDesc
      consult.value.illnessTime = consultIllness.illnessTime
      consult.value.consultFlag = consultIllness.consultFlag
      consult.value.pictures = consultIllness.pictures
    }
    // 选择患者
    const setPatientId = (patientId: string) => {
      consult.value.patientId = patientId
    }

    // 设置优惠券
    const setCouponId = (couponId: string) => {
      consult.value.couponId = couponId
    }

    // 清除问诊信息
    const clearConsult = () => {
      consult.value = {}
    }
    return {
      consult,
      setConsultType,
      setIllnessType,
      setDepId,
      setIllness,
      setPatientId,
      setCouponId,
      clearConsult,
    }
  },
  {
    persist: true,
  },
)
